import http from './http'

/**
 * @description 获取验证码
 * @route GET /common/captcha
 */
export const getCaptcha = () => {
  return http.get('/common/captcha')
}


/**
 * @description 管理员登录
 * @route POST /users/login
 */
export const login = (data) => {
  return http.post('/users/login', data)
}


/**
 * @description 商品列表
 * @route GET /storeItem
 */
export const productList = (data) => {
  return http.get('/storeItem', data)
}

/**
 * @description 商品新增
 * @route POST /storeItem
 */
export const productAdd = (data) => {
  return http.post('/storeItem', data)
}

/**
 * @description 商品详情
 * @route GET /storeItem/:id
 */
export const productDetail = (id) => {
  return http.get(`/storeItem/${id}`)
}

/**
 * @description 商品编辑
 * @route PUT /storeItem
 */
export const productEdit = (id, data) => {
  return http.put(`/storeItem/${id}`, data)
}

/**
 * @description 商品删除
 * @route DELETE /storeItem
 */
export const productDelete = (data) => {
  return http.delete(`/storeItem/${data.id}`)
}

/**
 * @description 商品删除
 * @route DELETE /storeItem
 */
export const uploadImage = (data) => {
  return http.post('/upload', data, { 'Content-Type': 'multipart/form-data' })
}

/**
 * @description 搜索商品
 * @route GET /storeItem/itemCode
 */
export const searchProduct = (data) => {
  return http.get('/storeItem/itemCode', data)
}

/**
 * @description 库存预警
 * @route GET /storeItem/alert
 */
export const getLowStockProducts = () => {
  return http.get('/storeItem/lowStock')
}

/**
 * @description 商品历史
 * @route GET /storeItem/history
 */
export const getProductHistory = (data) => {
  return http.get('/storeItem/records', data)
}

/**
 * @description 商品历史删除
 * @route DELETE /storeItem/records
 */
export const deleteProductHistoryById = (id) => {
  return http.delete(`/storeItem/records/${id}`)
}

export default {
  login,
  getCaptcha,
  productList,
  productAdd,
  productEdit,
  productDelete,
  uploadImage,
  productDetail,
  searchProduct,
  getLowStockProducts,
  getProductHistory,
  deleteProductHistoryById
}
